from django.db import models


# Create your models here.
class Province(models.Model):
    code = models.IntegerField(max_length=12, verbose_name='行政区划代码')
    name = models.CharField(max_length=32, default=None, verbose_name='名称')
    province = models.CharField(max_length=32, default=None, verbose_name='省、直辖市')
    city = models.CharField(max_length=32, default=None, verbose_name='市')
    area = models.CharField(max_length=32, default=None, verbose_name='区')
    town = models.CharField(max_length=32, default=None, verbose_name='城镇地区')

    class Meta:
        db_table = 'tb_province'
        verbose_name = '省市区-'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Area(models.Model):
    name = models.CharField(max_length=12, verbose_name='行政区划代码')
    """
    related_name:指明父级查询子级的语法

    """
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, related_name='subs', null=True)

    class Meta:
        db_table = 'tb_areas'
        verbose_name = '省市区'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
